home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / gameprt.exe / GAMEPORT.ASM < prev   
Assembly Source File  |  1991-08-18  |  5KB  |  110 lines

  1. ;**************************************************************************
  2. ;*                                                                        *
  3. ;*              Written by: Fred Richards (VE7FIT)                        *
  4. ;*                    Date: August 18, 1991                               *
  5. ;*                                                                        *
  6. ;*       This software is FREEWARE, as long as my name is given in        *
  7. ;*       the credits for the software developed using it.                 *
  8. ;*                                                                        *
  9. ;*       Assemble using Microsoft Macro Assembler                         *
  10. ;*                                                                        *
  11. ;*           MASM GAMEPORT;                                               *
  12. ;*                                                                        *
  13. ;*       or Borland Turbo Assembler                                       *
  14. ;*                                                                        *
  15. ;*           TASM GAMEPORT                                                *
  16. ;*                                                                        *
  17. ;**************************************************************************
  18.  
  19. ;**************************************************************************
  20. ;*                                                                        *
  21. ;*       The following routines allow the user to read the position       *
  22. ;*       of the Joy Stick. Typical numbers range from 8 to 300.           *
  23. ;*                                                                        *
  24. ;*                                   8  sticky()                          *
  25. ;*                                   |                                    *
  26. ;*                                   |                                    *
  27. ;*                           8 ----- * ----- 300 stickx()                 *
  28. ;*                                   |                                    *
  29. ;*                                   |                                    *
  30. ;*                                  300                                   *
  31. ;*                                                                        *
  32. ;**************************************************************************
  33.  
  34.         .MODEL  SMALL, C
  35.         .CODE
  36.  
  37.         PUBLIC  stickx, sticky, button1, button2
  38.  
  39. stickx  PROC    NEAR
  40.         push    dx              ; Save DX
  41.         push    bx              ; Save BX
  42.         mov     bx,0            ; Set initial count to zero
  43.         mov     dx,0201h        ; Set DX to game port
  44.         out     dx,al           ; Start the timers (Any output will do)
  45. stickx1:in      al,dx           ; Get port status
  46.         inc     bx              ; Increment counter
  47.         and     al,01h          ; Test if x-timer has timed out
  48.         jnz     short stickx1   ; Loop if not
  49.         mov     ax,bx           ; Load AX with counter value (for return)
  50.         pop     bx              ; Restore BX
  51.         pop     dx              ; Restore DX
  52.         ret
  53.  
  54. stickx  endp
  55.  
  56.  
  57. sticky  PROC    NEAR            ; See above for comments
  58.         push    dx
  59.         push    bx
  60.         mov     bx,0
  61.         mov     dx,0201h
  62.         out     dx,al
  63. sticky1:in      al,dx
  64.         inc     bx
  65.         and     al,02h          ; Test if y-timer has timed out
  66.         jnz     short sticky1
  67.         mov     ax,bx
  68.         pop     bx
  69.         pop     dx
  70.         ret
  71.  
  72. sticky  endp
  73.  
  74. ;**************************************************************************
  75. ;*                                                                        *
  76. ;*       The following routines allow the user to read the Joy Stick      *
  77. ;*       buttons. 0 = Not pressed, 1 = Pressed.                           *
  78. ;*                                                                        *
  79. ;**************************************************************************
  80.  
  81. button1 PROC    NEAR            ; This is normally the MAIN button
  82.         push    dx              ; Save DX
  83.         mov     dx,0201h        ; Load DX with game port address
  84.         mov     ah,0            ; Zero upper half of AX
  85.         in      al,dx           ; Read game port
  86.         not     al              ; Flip bits
  87.         and     al,10h          ; Mask to button #1
  88.         jz      buttonz         ; Skip if not pressed
  89.         mov     al,1            ; Set 1 for return value (button pressed)
  90. buttonz:pop     dx              ; Restore DX
  91.         ret
  92.  
  93. button1 endp
  94.  
  95. button2 PROC    NEAR            ; See above for comments
  96.         push    dx
  97.         mov     dx,0201h
  98.         mov     ah,0
  99.         in      al,dx
  100.         not     al
  101.         and     al,20h          ; Mask for button #2
  102.         jz      buttony
  103.         mov     al,1
  104. buttony:pop     dx
  105.         ret
  106.  
  107. button2 endp
  108.  
  109.         end
  110.